<?php
declare (strict_types = 1);

namespace app\common\cronscript;

use app\admin\service\BaseService;
use app\common\service\EmailService;

/**
 * 邮件发送任务
 *
 * @Author tanruizheng
 * @DateTime 2021-07-19
 */
class SendEmailScript extends CronScript
{
   public function run($cronId){
      $week = date('w',time());
      switch ($week) {
         case 1 || 3 || 5://周一 || 周三 || 周五
            $data = [
               '学习公众号PHP自学中心一篇文章',
               '学习laravel框架',
            ];
            break;
         case 2 || 4://周二 || 周四
            $data = [
               '学习公众号PHP自学中心一篇文章',
               '学习uniqpp框架',
            ];
            break;
         case 0 || 6://周二 || 周四
            $data = [
               '学习公众号PHP自学中心一篇文章',
               '王者荣耀',
               '追剧',
            ];
            break;
      }
      $weekArr = [
         '周日',
         '周一',
         '周二',
         '周三',
         '周四',
         '周五',
         '周六',
      ];
      // 5f98b62fb7b1983006b1422c78f9ac8b
      $content = implode('<br />',$data);
      $toMail = '1556050788@qq.com';
      $subject = '今天是'.$weekArr[$week].',别忘了今日打卡任务哦';
      $res = EmailService::sendEmail($toMail,$subject,$content);
      if($res['status']){
         return BaseService::createSuccess('ok');
      }
      return BaseService::createFail($res['msg']);
   }
}
